#include "Arrow.h"
#include "GameplayState.h"
#include "../SGD Wrappers/SGD_InputManager.h"

Arrow::Arrow()
{
	graphics = SGD::GraphicsManager::GetInstance();

	m_hImage = graphics->LoadTexture("resource/graphics/Pointer.png");
	
}

Arrow::~Arrow()
{
	graphics->UnloadTexture(m_hImage);
}

void Arrow::Render(float scale)
{
	SGD::Point camera;

	if (scale > 0)
	{
		camera = { m_ptPosition.x - GameplayState::GetInstance()->GetCamX(), m_ptPosition.y - GameplayState::GetInstance()->GetCamY() };
		graphics->DrawTexture(m_hImage, camera, m_fRotation, { 0, 16 }, {}, { scale, 1 });
	}
	else
	{
		camera = { m_ptPosition.x - GameplayState::GetInstance()->GetCamX() - 16, m_ptPosition.y - GameplayState::GetInstance()->GetCamY() };
		graphics->DrawTexture(m_hImage, camera, m_fRotation*scale, { 0, 16 }, {}, { scale, 1 });
	}
	
}

void Arrow::Input(float dt, float scale)
{
	SGD::InputManager* input = SGD::InputManager::GetInstance();

	SGD::Vector joystick = input->GetLeftJoystick(0);

	if (joystick.y < -0.5f)
	{
		m_fRotation = m_fRotation - (SGD::PI / 2 * dt);

		if (m_fRotation < -1.57f)
			m_fRotation = -1.57f;

		//SGD::Vector heading = { 0, -1*scale };
			//heading.Rotate(m_fRotation);

	}

	if (joystick.y > 0.5f)
	{
		m_fRotation = m_fRotation + (SGD::PI / 2 * dt);

		if (m_fRotation > 0.f)
			m_fRotation = 0.f;
	}
}